package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Company;
import com.ysd.util.DBManager;

public class CompanyDaoImpl { // 实现类,起名: 实体类名DaoImpl
	public Company getCompany() {
		// 1.建立连接
		Connection conn = DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		Company company = null;
		try {// 正常
				// 2.创建Statement对象
			st = conn.createStatement();
			// 3.sql语句
			String sql = "select * from company";
			// 4.执行sql语句
			rs = st.executeQuery(sql);// execute执行Query查询
			// 5.遍历结果集
			while (rs.next()) {
				String name = rs.getString("name");
				String webSite = rs.getString("webSite");
				String introduction = rs.getString("introduction");
				String phone = rs.getString("phone");
				String email = rs.getString("email");
				String address = rs.getString("address");
				String culture = rs.getString("culture");
				String logo = rs.getString("logo");
				company = new Company(name, webSite, introduction, phone, email, address, culture, logo);
			}
			return company;// 正常执行返回用户集合
		} catch (SQLException e) {// 异常
			e.printStackTrace();
			return null;// 异常执行返回空
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
	
	}
	
	/**
	 * @param com
	 * @return
	 */
	public int updateCompany(Company c) {
		String sql = "update company set name='"+c.getName()+"' , webSite='"+c.getWebSite()+"', introduction='"+c.getIntroduction()+"', phone="+c.getPhone()+", email='"+c.getEmail()+"', address='河南省周口市', culture='"+c.getCulture()+"' , logo='"+c.getLogo()+"'";
		System.out.println(sql);
		return DBManager.executeUpdate(sql);
	}

	
}
